<?php 
namespace Admin\Controller;

class CaseController extends BaseController
{	
	public function design_case()
	{
		$design_case = D("design_case");
			  
	      $design_case = $design_case -> select();
	     	 foreach ($design_case as $k => $v) {
	        $arr[$k] = $v;
	        $arr[$k]['img'] = "https://wxapp.renheyi.net".substr($v['img'], 8);
	   				 }
	  	$this -> assign('design_case', $arr);
		$this->display();
	}

    private function initEditor()
    {
        $this->assign("URL_upload", U('Admin/Ueditor/imageUp',array('savepath'=>'article')));
        $this->assign("URL_fileUp",U('Admin/Ueditor/fileUp',array('savepath'=>'article')));
        $this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp',array('savepath'=>'article')));
        $this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage',array('savepath'=>'article')));
        $this->assign("URL_imageManager", U('Admin/Ueditor/imageManager',array('savepath'=>'article')));
        $this->assign("URL_imageUp", U('Admin/Ueditor/imageUp',array('savepath'=>'article')));
        $this->assign("URL_getMovie", U('Admin/Ueditor/getMovie',array('savepath'=>'article')));
        $this->assign("URL_Home", "");
    }

	public function design_case_add()
	{
		
	 $design_case = D('design_case');
	        if ($_POST) {
	         	
	            $cfg = array('rootPath' => './../api/upload/equipment/', 'autoSub' => false, );

	            $upload = new \Think\Upload($cfg);
	                // 图片上传
	            $result = $upload -> upload($_FILES);
	            $bigpathname = $upload -> rootPath;
 
	                if (!$result) {// 上传错误提示错误信息
	                    $this -> error($upload -> getError());

	                } else {// 上传成功 获取上传文件信息
	                    foreach ($result as $file) {
	                        //图片地址
	                        $dizi = $bigpathname . $file['savepath'] . $file['savename'];
	                      
	                    }
	                }

	                 $arr = array('img' => $dizi, 'name' => $_POST['name'], 'parameter' => $_POST['parameter'],'apply' => $_POST['apply'] ,
	                 	'content' => $_POST['content'] 
	             );
	                   
	                $id = $design_case -> add($arr);
	                
	                if ($id) {
	                    $this -> success('新增成功', 'design_case');
	                }
	            } else {
	            	// 这个赋值页面
	              	$this->initEditor();
	                $this -> display();

	            }
	}
	/**
	设计案例删除

	**/
	public function design_case_delete($id)
	{
		$design_case = D('design_case');
        $id =   $design_case -> where("id = {$id}") -> delete();
        
        if($id){
            $this -> success('操作成功', U('Admin/Case/design_case'));
        }

	 $this->display();
	}
	/**
	设计案例修改

	**/
	public function design_case_save($id)
	{
		$design_case = D('design_case');
        if($_POST){

            $cfg = array('rootPath' => './../api/upload/equipment/', 'autoSub' => false, );

            $upload = new \Think\Upload($cfg);
                // 图片上传
            $result = $upload -> upload($_FILES);
            $bigpathname = $upload -> rootPath;

                if (!$result) {// 上传错误提示错误信息

                    $design_cases = $design_case -> where("id = {$id}") -> find();
                    $dizi =$design_cases['img'];
                
                } else {// 上传成功 获取上传文件信息
                    foreach ($result as $file) {
                        //图片地址
                        $dizi = $bigpathname . $file['savepath'] . $file['savename'];
                    }
                }

               $arr = array('img' => $dizi, 'name' => $_POST['name'], 'content' => $_POST['content']);
               
           $id = $design_case -> where("id = {$id}") -> save($arr);
                
                if($id){
                    $this -> success('新增成功', U('Admin/Case/design_case'));
                }
             }else{

                $design_case  = $design_case -> where("id = {$id}") -> find();
                $design_case['img'] = "https://wxapp.renheyi.net".substr($design_case['img'], 8);
                $this -> assign('info', $design_case);
                $this -> display();

             }
	}





	
/**
客户案例显示

**/
	public function customer_case()
	{
		$customer_case = D("customer_case");
	  
	      $customer_case = $customer_case -> select();
	     	 foreach ($customer_case as $k => $v) {
	        $arr[$k] = $v;
	        $arr[$k]['img'] = "https://wxapp.renheyi.net".substr($v['img'], 8);
	   				 }
	   		$abb = count($arr);
	   		
	  	$this -> assign('customer_case', $arr);
	  	$this -> assign('abb', $abb);
		
		$this->display();
	}
	/**
	客户案例添加

	**/
	public function customer_case_add()
	{

		 $customer_case = D('customer_case');
	        if ($_POST) {
	         
	            $cfg = array('rootPath' => './../api/upload/equipment/', 'autoSub' => false, );

	            $upload = new \Think\Upload($cfg);
	                // 图片上传
	            $result = $upload -> upload($_FILES);
	            $bigpathname = $upload -> rootPath;

	                if (!$result) {// 上传错误提示错误信息
	                    $this -> error($upload -> getError());

	                } else {// 上传成功 获取上传文件信息
	                    foreach ($result as $file) {
	                        //图片地址
	                        $dizi = $bigpathname . $file['savepath'] . $file['savename'];
	                    }
	                }

	                 $arr = array('img' => $dizi, 'name' => $_POST['name'], 'content' => $_POST['content']);
	                   
	                $id = $customer_case -> add($arr);
	                
	                if ($id) {
	                    $this -> success('新增成功', 'customer_case');
	                }
	            } else {

	              
	                $this -> display();

	            }
	}
	/**
	客户案例删除

	**/
	public function customer_case_delete($id)
	{

		 $customer_case = D('customer_case');
        $id =   $customer_case -> where("id = {$id}") -> delete();
        
        if($id){
            $this -> success('操作成功', U('Admin/Case/customer_case'));
        }
	 $this->display();
	}
	/**
	客户案例修改

	**/
	public function customer_case_save($id)
	{
$customer_case = D('customer_case');
       if($_POST){

            $cfg = array('rootPath' => './../api/upload/equipment/', 'autoSub' => false, );

            $upload = new \Think\Upload($cfg);
                // 图片上传
            $result = $upload -> upload($_FILES);
            $bigpathname = $upload -> rootPath;

                if (!$result) {// 上传错误提示错误信息

                    $customer_cases = $customer_case -> where("id = {$id}") -> find();
                    $dizi =$customer_cases['img'];
                
                } else {// 上传成功 获取上传文件信息
                    foreach ($result as $file) {
                        //图片地址
                        $dizi = $bigpathname . $file['savepath'] . $file['savename'];
                    }
                }

               $arr = array('img' => $dizi, 'name' => $_POST['name'], 'parameter' => $_POST['parameter'],   'apply' => $_POST['apply'], 'content' => $_POST['content']);
               
           $id = $customer_case -> where("id = {$id}") -> save($arr);
                
                if($id){
                    $this -> success('新增成功', U('Admin/Case/customer_case'));
                }
            }else{

                $customer_case  = $customer_case -> where("id = {$id}") -> find();
                $customer_case['img'] = "https://wxapp.renheyi.net".substr($customer_case['img'], 8);
                $this -> assign('info', $customer_case);
                $this -> display();

            }
	}







	}